<template>
  <div class="container">
    <!-- 上半部分：统计信息 -->
    <div class="stats-container">
      <!-- 左侧统计 -->
      <div class="left-stats">
        <div class="stat-item">
          <div class="stat-label">总数量</div>
          <div class="stat-value1 total">{{ totalCount }}</div>
        </div>
        <div class="stat-item">
          <div class="stat-label">在线数量</div>
          <div class="stat-value1 online">{{ onlineCount }}</div>
        </div>
        <div class="stat-item">
          <div class="stat-label">离线数量</div>
          <div class="stat-value1 offline">{{ offlineCount }}</div>
        </div>
      </div>
      
      <!-- 竖线分隔符 -->
      <div class="divider"></div>
      
      <!-- 右侧统计 - 修改为上下各两个，名称在文本框左侧 -->
      <div class="right-stats">
        <div class="grid-container">
          <div class="grid-row">
            <div class="grid-item">
              <span class="stat-label">运行：</span>
              <div class="stat-value running">{{ runningCount }}</div>
            </div>
            <div class="grid-item">
              <span class="stat-label">故障：</span>
              <div class="stat-value fault">{{ faultCount }}</div>
            </div>
          </div>
          <div class="grid-row">
            <div class="grid-item">
              <span class="stat-label">待机：</span>
              <div class="stat-value standby">{{ standbyCount }}</div>
            </div>
            <div class="grid-item">
              <span class="stat-label">空闲：</span>
              <div class="stat-value idle">{{ idleCount }}</div>
            </div>
          </div>
        </div>
      </div>
    </div>

    <!-- 下半部分：数据表格 -->
    <div class="data-table">
      <table>
        <thead>
          <tr>
            <th v-for="column in columns" :key="column.key">{{ column.title }}</th>
          </tr>
        </thead>
        <tbody>
          <tr v-for="(item, index) in tableData" :key="index">
            <td v-for="column in columns" :key="column.key">
              {{ item[column.key] }}
            </td>
          </tr>
        </tbody>
      </table>
    </div>
  </div>
</template>

<script>
export default {
  name: 'DashboardPage',
  data() {
    return {
      // 统计数字
      totalCount: 42,
      onlineCount: 36,
      offlineCount: 6,
      runningCount: 15,
      faultCount: 2,
      standbyCount: 10,
      idleCount: 9,
      
      // 表格列配置
      columns: [
        { key: 'id', title: 'ID' },
        { key: 'name', title: '设备名称' },
        { key: 'status', title: '状态' },
        { key: 'location', title: '位置' },
        { key: 'lastUpdate', title: '最后更新时间' }
      ],
      
      // 表格数据
      tableData: [
        { id: 1, name: '设备A', status: '运行中', location: '区域1', lastUpdate: '2023-08-15 10:30' },
        { id: 2, name: '设备B', status: '待机', location: '区域2', lastUpdate: '2023-08-15 09:45' },
        { id: 3, name: '设备C', status: '空闲', location: '区域1', lastUpdate: '2023-08-15 11:20' },
        { id: 4, name: '设备D', status: '故障', location: '区域3', lastUpdate: '2023-08-15 08:15' },
        { id: 5, name: '设备E', status: '运行中', location: '区域2', lastUpdate: '2023-08-15 10:55' }
      ]
    };
  }
};
</script>

<style scoped>
.container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  font-family: Arial, sans-serif;
  padding: 20px;
  box-sizing: border-box;
}

.stats-container {
  display: flex;
  height: 25%;
  margin-bottom: 25px;
  background-color: white;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  padding: 15px;
}

.left-stats {
  display: flex;
  flex: 1;
  justify-content: space-around;
}

.right-stats {
  flex: 1;
  display: flex;
  padding-left: 25px;
}

/* 右侧网格布局 */
.grid-container {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
}

.grid-row {
  display: flex;
  flex: 1;
  justify-content: space-around;
}

.grid-item {
  display: flex;
  align-items: center; /* 垂直居中 */
  justify-content: flex-start; /* 左对齐 */
  flex: 1;
  padding: 0 15px;
}

/* 左右分隔竖线 */
.divider {
  width: 1px;
  background-color: #e0e0e0;
  margin: 10px 25px;
}

/* 左侧统计项样式 */
.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 10px;
  min-width: 100px;
}

.stat-label {
  font-size: 14px;
  color: #666;
  margin-bottom: 8px;
  font-weight: 500;
}

/* 右侧统计项样式 */
.grid-item .stat-label {
  font-size: 15px;
  color: #555;
  font-weight: 500;
  margin-right: 12px; /* 标签与数值框之间的间距 */
  min-width: 50px; /* 确保标签宽度一致 */
  text-align: right; /* 标签文本右对齐 */
}

/* 统计值通用样式 */
.stat-value1 {
  min-width: 200px;
  height: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  font-size: 22px;
  font-weight: bold;
  color: white;
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
  transition: transform 0.3s ease;
}
.stat-value {
  min-width: 100px;
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  font-size: 22px;
  font-weight: bold;
  color: white;
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
  transition: transform 0.3s ease;
}
.stat-value:hover {
  transform: translateY(-3px);
}

/* 不同状态框的颜色 */
.total { background: linear-gradient(135deg, #4a6fa5, #3a5a8c); }
.online { background: linear-gradient(135deg, #4caf50, #388e3c); }
.offline { background: linear-gradient(135deg, #f44336, #d32f2f); }
.running { background: linear-gradient(135deg, #2196f3, #1976d2); }
.fault { background: linear-gradient(135deg, #ff9800, #f57c00); }
.standby { background: linear-gradient(135deg, #9c27b0, #7b1fa2); }
.idle { background: linear-gradient(135deg, #607d8b, #455a64); }

.data-table {
  flex: 1;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 2px 10px rgba(0,0,0,0.05);
}

table {
  width: 100%;
  border-collapse: collapse;
}

th {
  background-color: #f5f7fa;
  padding: 15px 20px;
  text-align: left;
  font-weight: 600;
  color: #2c3e50;
  border-bottom: 2px solid #e0e0e0;
}

td {
  padding: 12px 20px;
  border-bottom: 1px solid #eee;
}

tbody tr:hover {
  background-color: #f5f9ff;
}

tbody tr:nth-child(even) {
  background-color: #fafafa;
}

/* 响应式调整 */
@media (max-width: 768px) {
  .stats-container {
    flex-direction: column;
    height: auto;
  }
  
  .divider {
    width: 100%;
    height: 1px;
    margin: 15px 0;
  }
  
  .left-stats {
    margin-bottom: 15px;
  }
  
  .right-stats {
    padding-left: 0;
  }
  
  .grid-container {
    width: 100%;
  }
  
  .grid-row {
    margin-bottom: 10px;
  }
  
  /* 移动端右侧统计项改为垂直布局 */
  .grid-item {
    flex-direction: column;
    align-items: flex-start;
  }
  
  .grid-item .stat-label {
    margin-bottom: 5px;
    text-align: left;
  }
}
</style>